package com.fire.social.mapper;

import com.fire.social.entity.relationship.Praised;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface PraiseMapper extends Neo4jRepository<Praised, Long> {

    @Query("match (user:User) where user.account=$account \n" +
            "match (content:Content) where ID(content)=$contentId\n" +
            "create (content)-[praised:Praised]->(user) return ID(praised)")
    Long praisedIt(@Param("account") String account, @Param("contentId") Long contentId);

    @Query("match (user:User) where user.account=$account \n" +
            "match (content:Content) where ID(content)=$contentId\n" +
            "match (content)-[praised:Praised]->(user) delete praised return count(praised)")
    Integer canclepraised(@Param("account") String account, @Param("contentId") Long contentId);

    @Query("match (content:Content) where ID(content)=$contentId\n" +
            "match (content)-[:Praised]->(user) return count(user)")
    Long getPraisedNumber(@Param("contentId") Long contentId);

    @Query("match (content:Content) where ID(content)=$contentId\n" +
            "match (content)-[:Praised]->(user) where user.account=$account return count(user)")
    Integer isPraised(@Param("contentId") Long contentId, @Param("account") String account);

}
